package com.ruoyi.eqmonitor.utils;




import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class SecretTool {

    private static final String key = "1a2bc34dik89jhy6";

    public static String encrypt(String data) throws Exception {
        Cipher cipher = Cipher.getInstance("AES");
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] encrypted = cipher.doFinal(data.getBytes());
        return Base64.getEncoder().encodeToString(encrypted);
    }
    public static String decrypt(String encryptedData) throws Exception {
        Cipher cipher = Cipher.getInstance("AES");
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        byte[] decrypted = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
        return new String(decrypted).replace("\n","").replace("\t","");
    }

    public static void main(String[] args) throws Exception {
        String s = "WRw6J5orBTmYzMDE4UPainH82LsI9e/h9JqGp8v1CGrFdNY6z85lSq0cxqbgZwPunDy4/p/rTpIiKi4dm3MtgLBnTJX4H6bTnZ7/4T5FKIxtacIryT0BFTyGtNQHjf+Ay3+MfBViYoqqpc+OUtjoQEJAHJ/cn3ImfJ4HAdVoJSVzOkfxpgaAbITBx45CZ/vMquzMhSNhd9ugJl9IX0QdfFCrHL+8wdIsa/Rr8XLQQDTgwUQM5l8rVpHBHu4u42W/RPvbcT8F60i7U8tl7Kl3pQ/uG68hM/S2j0HMcp6Vyiny1txT1XriQg1n9Z3EbywqQQ10skmMb9cHIlLe2peD4k1yBPpaIBemHPYLEVQaVxE=    ";

        System.err.println(SecretTool.decrypt(s));
    }
}
